﻿
/// <reference path="../Ext4.0/ext-all.js" />
//setTimeout(function () {
//    Ext.get('loading').remove();
//    Ext.get('loading-mask').fadeOut({ remove: true });
//}, 1000);

Ext.BLANK_IMAGE_URL = "image/s.gif";
Ext.QuickTips.init();


Ext.onReady(function () {

    Ext.form.Field.prototype.msgTarget = 'side';
    var dr = Ext.create('Ext.form.Panel', {
        renderTo: 'tr',
        frame: true,
        title: '用户登录',
        buttonAlign: 'center',
        iconCls: 'loginicon',
        bodyStyle: 'background: White;padding:10 0 0 10;',
        height: 250,
        width: 450,
        defaultType: 'textfield',
        items: [
                 {
                    margin: "-0 0 0 20",
                    id: 'name',
                    value:'',
                    fieldLabel: '   用户名',
                    name: 'name', //元素名称  
                    allowBlank: false, //不允许为空  
                    iconCls: 'table_login',
                    blankText: '用户名不能为空'//错误提示内容  
                },
                {
                    margin: "20 0 0 20",
                    id: 'password',
                    value:'',
                    inputType: 'password',
                    fieldLabel: '   密　码',
                    maxLength: 10,
                    name: 'password',
                    allowBlank: false,

                    blankText: '密码不能为空'
                }, {
                    margin: "20 0 0 20",
                    xtype: 'radiogroup',
                    columns: 1,
                    vertical: true,
                    id:'role',
                    name:'role',
                    fieldLabel: '用户类型',
                    items: [
                        { boxLabel: '工作人员', name: 'role', inputValue: 0, checked: true }
                    ]
                }
        ],
        buttons: [{

            text: '登录',
            type: 'submit',
            id: 'sb',
            //定义表单提交事件  
            handler: function () {
                save();
            }
        }, {
            text: '重置',
            handler: function () {
                dr.form.reset();
            }
        }],
        keys: [{
            key: Ext.EventObject.ENTER,
            fn: save,
            scope: this
        }]
    });

    function save() {
        var name = Ext.getCmp('name').getValue();
        var password = Ext.getCmp('password').getValue();
        var role = Ext.getCmp('role').getValue().role;
        //验证合法后使用加载进度条  
        if (dr.form.isValid()) {
            //提交到服务器操作  
            dr.form.submit({
                waitMsg: '正在进行登陆验证,请稍后...',
                url: 'Login.aspx?action=check',
                method: 'post',
                params: {
                    name: name,
                    password: password,
                    role: role
                },
                //提交成功的回调函数  
                success: function (form, action) {
                    if (action.result.msg == '登陆成功') {
                        window.location.href = "MainForm.aspx";
                    } else if (action.result.msg == '登陆失败') {
                        Ext.Msg.alert('错误提示', '登陆失败用户信息有误！');
                    }
                },
                //提交失败的回调函数  
                failure: function (form, action) {
                    switch (action.failureType) {
                        case Ext.form.Action.CLIENT_INVALID:
                            Ext.Msg.alert('错误提示', '表单数据非法请核实后重新输入！');
                            break;
                        case Ext.form.Action.CONNECT_FAILURE:
                            Ext.Msg.alert('错误提示', '网络连接异常！');
                            break;
                        case Ext.form.Action.SERVER_INVALID:
                            Ext.Msg.alert('错误提示', "您的输入用户信息有误，请核实后重新输入！");
                            simple.form.reset();
                    }
                }
            });
        }
    }; 
});